// 切换 登录，忘记密码，注册界面
jQuery(function ($) {

    $(document).on('click', '.toolbar a[data-target]', function (e) {
        e.preventDefault();
        var target = $(this).data('target');
        $('.widget-box.visible').removeClass('visible');//hide others
        $(target).addClass('visible');//show target
    });
});

// 广发通登录
jQuery(function ($) {

    $.xumf.openLoginFrame();
    /*var $register = $('#signup-box').find('form');
    $register.validate({
        rules: {
            email: {
                required: true
            },
            loginName: {
                required: true,
                maxlength: 20
            },
            password: {
                required: true,
                minlength: 6,
                maxlength: 100
            },
            confirmPassword: {
                equalTo: '#register_password'
            }
        },
        messages: {
            confirmPassword: {
                equalTo: '密码不一致'
            }
        },
        errorElement: "em",
        submitHandler: function (form) {
            // 加密前密码
            var beforeVal = $('#register_password').val();
            // 加密后密码
            var afterVal = $.xumf.encrypt(beforeVal);
            // 设置值为密码的值为aes加密后
            $register.find('input[name=password][type=hidden]').val(afterVal);
            $(form).ajaxSubmit({
                success: function (res) {
                    if (res.success) {
                        window.location = '/';
                    } else {
                        layer.alert(res.detailMsg);
                    }
                }
            });
        }
    });*/
});

// 忘记密码
jQuery(function ($) {

    var $forgetForm = $('#forgot-box').find('form');
    $forgetForm.validate({
        rules: {
            email: {
                required: true
            }
        },
        errorElement: "em",
        submitHandler: function (form) {

            layer.alert("修改密码成功");
        }
    });
});

// 登录
jQuery(function ($) {
    var $loginForm = $('#login-box').find('form');
    $loginForm.validate({
        rules: {
            loginName: {
                required: true,
                maxlength: 20
            },
            password: {
                required: true,
                minlength: 6,
                maxlength: 100
            }
        },
        errorElement: "em",
        submitHandler: function (form) {
            // 加密前密码
            var beforeVal = $loginForm.find('input[type=password]').val();
            // 加密后密码
            var afterVal = $.xumf.encrypt(beforeVal);
            // 设置值为密码的值为aes加密后
            $loginForm.find('input[name=password][type=hidden]').val(afterVal);
            // $('body').ace_ajax('startLoading');
            $(form).ajaxSubmit({
                success: function (res) {
                    if (res.success) {
                        window.location = '/' + window.location.hash;
                    } else {
                        $.xumf.gritter(res);
                    }
                }
            });
        }
    });
    // 回车事件
    $loginForm.bind('keyup', 'enter', function (e) {
        // 当前是否显示登录
        var hasClass = $('#login-box').hasClass('visible');
        if (hasClass) {
            $loginForm.find('button[type=submit]').trigger("click");
        }
        e.preventDefault();
    });
});

